<?php

require_once dirname(dirname(__FILE__)) . '/config/config.php';
require_once dirname(dirname(__FILE__)) . '/config/connection.php';

/**
 * User: Viet Anh
 * Date: 13/06/2014
 * Time: 00:47
 */
class dao_roulette_game
{
    public function get_list()
    {
        $db  = new connection();
        $con = $db->open_connect();

        $query = "SELECT * FROM tbl_roulette_game";
        $result = mysqli_query($con, $query) or die("Query fail: " . mysqli_error());

        $list = array();
        while ($row = mysqli_fetch_array($result)) {
            array_push($list, $row);
        }

        $db->close_connect();

        return $list;
    }

    public function find($id)
    {
        $db  = new connection();
        $con = $db->open_connect();

        $query = "SELECT * FROM tbl_roulette_game WHERE id = $id";
        $result = mysqli_query($con, $query) or die("Query fail: " . mysqli_error());
        $row = mysqli_fetch_array($result);
        $db->close_connect();

        return $row;
    }

    public function insert($name)
    {
        $db  = new connection();
        $con = $db->open_connect();

        $query = "INSERT INTO tbl_roulette_game(name) VALUES ('$name')";
        mysqli_query($con, $query) or die("Query fail: " . mysqli_error());
        $db->close_connect();

        return TRUE;
    }

    public function update($id, $name)
    {
        $db  = new connection();
        $con = $db->open_connect();

        $query = "UPDATE tbl_roulette_game SET name = '$name' WHERE id = $id";
        mysqli_query($con, $query) or die("Query fail: " . mysqli_error());
        $db->close_connect();

        return TRUE;
    }

    public function delete($id)
    {
        $db  = new connection();
        $con = $db->open_connect();

        $query = "DELETE FROM tbl_roulette_game WHERE id = $id";
        mysqli_query($con, $query) or die("Query fail: " . mysqli_error());
        $db->close_connect();

        return TRUE;
    }
}